/**
 * 您的公司.com
 * Copyright (c) 2018-2018 All Rights Reserved.
 */
package com.mei.demo.reflect;

/**
 * 
 *
 * @author mei.xiaoliang@qq.com
 */
public class Factory {

    public static void main(String[] args) {

        RefelctDog dog = getInstance("com.mei.demo.reflect.RefelctDog", RefelctDog.class);
        System.out.println("反射拿狗: " + dog);

        RefelctCat cat = getInstance("com.mei.demo.reflect.RefelctCat", RefelctCat.class);
        System.out.println("反射拿猫: " + cat);

    }

    public void settttttttttttttt() {

    }

    /**
     * 
     * @param className 类路径
     * @param clazz     类
     * @return
     */
    @SuppressWarnings("unchecked")
    private static <T> T getInstance(String className, Class<T> clazz) {
        T instance = null;
        try {
            instance = (T) Class.forName(className).newInstance();
        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
            e.printStackTrace();
        }
        return instance;
    }

}
